/**
 * 系统平台
 * moonvip_admin
 * com.tz.web.metalcalculation
 * MetalCalculationController.java
 * 创建人:小胡
 * 时间：2017年02月08日 14:10:20
 *
 */
package com.tz.web.metalcalculation;

import com.tz.auth.AuthPassport;
import com.tz.bean.MetalCalculation;
import com.tz.bean.TzParams;
import com.tz.service.metalcalculation.IMetalCalculationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

/**
 * 贵金属计算公式参数管理web
 * MetalCalculationController
 * 创建人:小胡
 * 时间：2017年02月08日 14:10:20
 * @version 1.0.0
 * 
 */
@Controller
@RequestMapping("/admin/service/metalcalculation")
public class MetalCalculationController {
	
	@Autowired
	private IMetalCalculationService metalcalculationService;

	/*列表查询*/
	@AuthPassport
	@RequestMapping("/list")
	public String list(TzParams params){
		return "service/metalcalculation/list";
	}

    /*模板页面*/
	@RequestMapping("/template")
	public String template(TzParams params ,Model model){
		params.setDeleteCode("001");
		model.addAttribute("datas", metalcalculationService.findMetalCalculations(params));
		model.addAttribute("itemCount", metalcalculationService.count(params));
		return "service/metalcalculation/template";
	}



	@AuthPassport
	@RequestMapping("/add")
    public String add(TzParams params, Model model){
		//查询得到所有的类型
		List<HashMap<String, Object>>  metals = metalcalculationService.listMetals();
		model.addAttribute("metals", metals);
		return "service/metalcalculation/add";
   }

   @AuthPassport
   @RequestMapping(value = "/edit/{id}", method = RequestMethod.GET)
    public String edit(@PathVariable("id") Integer id, Model model){
		HashMap<String ,Object> metalcalculation = metalcalculationService.getMetalCalculation(id);
		List<HashMap<String, Object>>  metals = metalcalculationService.listMetals();
		model.addAttribute("metals", metals);
		model.addAttribute("metalcalculation",metalcalculation);
		return "service/metalcalculation/edit";
	}

	@AuthPassport
	@ResponseBody
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	public String delete(TzParams params){
		metalcalculationService.delete(params);
		return "success";
	}

	@ResponseBody
	@RequestMapping(value="/save",method=RequestMethod.POST)
	public int save(MetalCalculation metalcalculation){
		int n = metalcalculationService.save(metalcalculation);
		return n;
	}

	@ResponseBody
	@RequestMapping(value="/update",method= RequestMethod.POST)
	public int update(MetalCalculation metalcalculation){
		int n = metalcalculationService.update(metalcalculation);
		return n;
	}

	//异步查询得到所有的系列
	@ResponseBody
	@RequestMapping("/listSeriesByMetalCode")
	public List<HashMap<String, Object>>  listSeriesByMetalCode(String codevalue){
		List<HashMap<String , Object>> list =   metalcalculationService.listSeries(codevalue);
		return list;
	}

	@ResponseBody
	@RequestMapping("/getCountRecord")
	public int  getCountRecord(MetalCalculation metalCalculation){
		int n =   metalcalculationService.getCountRecord(metalCalculation);
		return n;
	}
}
